<!DOCTYPE html>
<html>
<head>
<title>管理员列表</title>
<#include "/header.html">
</head>
<style>
	#container {width:400px; height: 300px; }
</style>
<body>
<div id="rrapp" v-cloak>
	<div v-show="showList">
		<div class="grid-btn">
			<div class="form-group col-sm-2">
				<input type="text" class="form-control" v-model="q.username" @keyup.enter="query" placeholder="用户名">
			</div>
			<a class="btn btn-default" @click="query">查询</a>
			<#if shiro.hasPermission("sys:user:save")>
			<a class="btn btn-primary" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</a>
			</#if>
			<#if shiro.hasPermission("sys:user:update")>
			<a class="btn btn-primary" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</a>
			</#if>
			<#if shiro.hasPermission("sys:user:delete")>
			<a class="btn btn-primary" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
			</#if>
		</div>
	    <table id="jqGrid"></table>
	    <div id="jqGridPager"></div>
    </div>

	<div v-show="!showList" class="panel panel-default">
		<div class="panel-heading">{{title}}</div>
		<form class="form-horizontal">
			<div class="form-group">
				<div class="col-sm-2 control-label">用户名</div>
				<div class="col-sm-10">
					<input type="text" class="form-control" v-model="user.username" placeholder="登录账号"/>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-2 control-label">所属部门</div>
				<div class="col-sm-10">
					<input type="text" class="form-control" style="cursor:pointer;" v-model="user.deptName" @click="deptTree" readonly="readonly" placeholder="所属部门"/>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-2 control-label">密码</div>
				<div class="col-sm-10">
					<input type="text" class="form-control" v-model="user.password" placeholder="密码"/>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-2 control-label">邮箱</div>
				<div class="col-sm-10">
					<input type="text" class="form-control" v-model="user.email" placeholder="邮箱"/>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-2 control-label">手机号</div>
				<div class="col-sm-10">
					<input type="text" class="form-control" v-model="user.mobile" placeholder="手机号"/>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-2 control-label">分佣比例</div>
				<div class="col-sm-10">
					<input type="text" class="form-control" v-model="user.commission" placeholder="分佣比例"/>
					<span style="position: absolute;right: 22px;top: 8px;color: #4C4948;line-height: 1.5;">%</span>
				</div>
			</div>
			<div class="form-group" id="roles">
				<div class="col-sm-2 control-label">角色</div>
				<div class="col-sm-10">
					<label v-for="role in roleList" class="checkbox-inline">
						<input type="checkbox" :value="role.roleId" v-model="user.roleIdList">{{role.roleName}}
					</label>
				</div>
			</div>
			<div id="merchantid" >
				<div class="form-group">
					<div class="col-sm-2 control-label">商户名称</div>
					<div class="col-sm-10">
						<input type="text" class="form-control" v-model="merchant.name" placeholder="商户名称"/>
					</div>
				</div>

				<div class="form-group">
					<div class="col-sm-2 control-label">详细地址</div>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="address" v-model="merchant.address" placeholder="详细地址"/>
					</div>
				</div>

				<div class="form-group" >
					<div class="col-sm-2 control-label"></div>
					<div class="col-sm-10" style="width: 400px; height: 300px; border: 1px solid rgb(222, 229, 231);">
						<div id="container"></div>
					</div>

				</div>
				<div class="form-group">
					<div class="col-sm-2 control-label">经度</div>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="longitude" v-model="merchant.longitude" placeholder="经度"/>
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-2 control-label">纬度</div>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="latitude" v-model="merchant.latitude" placeholder="纬度"/>
					</div>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-2 control-label"></div>
				<input type="button" class="btn btn-primary" @click="saveOrUpdate" value="确定"/>
				&nbsp;&nbsp;<input type="button" class="btn btn-warning" @click="reload" value="返回"/>
			</div>
		</form>
	</div>
</div>

<!-- 选择部门 -->
<div id="deptLayer" style="display: none;padding:10px;">
	<ul id="deptTree" class="ztree"></ul>
</div>


<script src="${request.contextPath}/statics/js/modules/sys/user.js?_${.now?long}"></script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=4029717ca31161b790024bdede163f3c&plugin=Amap.Geocoder"></script>

<script type="text/javascript">

    var map = new AMap.Map("container", {
        resizeEnable: true,
        zoom: 10,
        center: [114.3162001,30.58108413], //初始地图中心点
    });
    var geocoder;

    var convertor ;
    AMap.plugin(["AMap.Geocoder"],function () {
        geocoder = new AMap.Geocoder({
            city: "027", //城市设为北京，默认：“全国”
            radius: 1000, //范围，默认：500
        });
    });

    /*AMap.plugin(["AMap.Constructor"],function () {
        convertor = new AMap.Constructor({

        });
    });*/

    /*var point;
    AMap.plugin(["AMap.Point"],function () {
        point = new AMap.Point({

        });
    });*/

    var marker = new AMap.Marker();
    function regeoCode(lnglat) {

        map.add(marker);
        marker.setPosition(lnglat);

        $("#longitude").val(lnglat.lng);
        $("#latitude").val(lnglat.lat);


        geocoder.getAddress(lnglat, function(status, result) {
            if (status === 'complete'&&result.regeocode) {
                var address = result.regeocode.formattedAddress;
                $("#address").val(address);

            }else{
                log.error('根据经纬度查询地址失败')
            }
        });
    }

    map.on('click',function(e){
        regeoCode(e.lnglat);
    });

    /*translateCallback = function (data) {
		if(data.status == 0){
            console.log(data.points[0]);
            $("#longitude").val(data.points[0].lng);
            $("#latitude").val(data.points[0].lat);

		}
    }

    function transPoint(point) {
        convertor.translate(point,1,5,translateCallback);
    }*/
</script>
</body>
</html>